import React, { Component } from 'react';
import { View } from 'react-native';

import Theme from '../../../../native-base-theme/variables/commonColor';

import MaintainComplete from './maintainComplete';
import SendBack from './sendBack';
import SendBackAndStop from './sendBackAndStop';
import CheckAndAccept from './checkAndAccept';
import ZlstIcon from '../../../../components/zlst-icons';

class submitPage extends Component {
  static navigationOptions = ({ navigation }) => ({
    title: navigation.state.params.titleStr,
    headerStyle: { backgroundColor: Theme.toolbarDefaultBg },
    headerTintColor: '#FFFFFF',
    headerTitleStyle: {
      fontWeight: 'bold',
      fontSize: 20,
      flex: 1,
      textAlign: 'center',
    },
    headerBackImage: (
      <ZlstIcon
        name="fanhui"
        size={24}
        color="white"
      />
    ),
    headerRight: <View />,
  });

  _mobileInfo = {}

  id = ''

  constructor(props) {
    super(props);
    this.state = {};
  }

  componentWillMount() {
    this._mobileInfo = this.props.navigation.state.params.mobileInfo;
    this.id = this.props.navigation.state.params.id;
  }

  _back = () => {
    // 刷新上级页面
    if (this.props.navigation.state.params._refresh) {
      this.props.navigation.state.params._refresh();
    }

    // 路由返回
    this.props.navigation.goBack();
  }

  _getPage = () => {
    const { type } = this.props.navigation.state.params;
    const { equipObjType, equipmentId, failureKeywordsId, facilityId, failureType, deviceMaintOrgId } = this.props.navigation.state.params;

    let page = null;
    if (type === 'maintainComplete') {
      page = (<MaintainComplete
        mobileInfo={this._mobileInfo}
        id={this.id}
        back={this._back}
        equipObjType={equipObjType}
        equipmentId={equipmentId}
        failureKeywordsId={failureKeywordsId}
        facilityId={facilityId}
        deviceMaintOrgId={deviceMaintOrgId}
        failureType={failureType}
      />
      );
    } else if (type === 'SendBack') {
      page = (
        <SendBack
          mobileInfo={this._mobileInfo}
          id={this.id}
          back={this._back}
        />
      );
    } else if (type === 'checkAndAccept') {
      page = (
        <CheckAndAccept
          mobileInfo={this._mobileInfo}
          id={this.id}
          back={this._back}
        />
      );
    } else if (type === 'SendBackAndStop') {
      page = (
        <SendBackAndStop
          mobileInfo={this._mobileInfo}
          id={this.id}
          back={this._back}
        />
      );
    }
    return page;
  }

  render() {
    return (
      <View style={{ display: 'flex', flex: 1 }}>
        {this._getPage()}
      </View>
    );
  }
}

export default submitPage;
